<template>
	<view class="index-singleranksetting">
		<view class="index-singleranksetting-header">
			对另一半的要求
		</view>
		<scroll-view class="" scroll-y="true" style="height: 900rpx;">
			<view class="index-singleranksetting-main">
				<view class="index-singleranksetting-main-title">
					基本筛选
				</view>
				<!-- 年龄 -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						年龄
					</view>
					<view class="index-singleranksetting-main-item-content">
						<range-slider :blockSize="32" width="680" step="2" :values="ageRange" max="50" min="18"
							liveMode="true" @rangechange="onchangeAge"></range-slider>
						<view class="u-flex u-row-between">
							<view class="">
								{{ ageRange[0] }}岁
							</view>
							<view class="">
								{{ ageRange[1] }}岁
							</view>
						</view>
					</view>
				</view>
				<!-- 身高 -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						身高
					</view>
					<view class="index-singleranksetting-main-item-content">
						<range-slider :blockSize="32" width="680" step="5" :values="tallRange" max="210" min="160"
							liveMode="true" @rangechange="onchangeTall"></range-slider>
						<view class="u-flex u-row-between">
							<view class="">
								{{ tallRange[0] }}cm
							</view>
							<view class="">
								{{ tallRange[1] }}cm
							</view>
						</view>
					</view>
				</view>
				<!-- 学历 -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						学历
					</view>
					<view class="index-singleranksetting-main-item-content">
						<view class="index-singleranksetting-main-item-content-checkbox"
							:class="educationId == item.id ? 'act' : ''" v-for="(item, index) in educationList" :key="index"
							@click="educationId = item.id">
							{{ item.name }}
						</view>
					</view>
				</view>
				<!-- 婚烟状态 -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						婚姻状态
					</view>
					<view class="index-singleranksetting-main-item-content">
						<view class="index-singleranksetting-main-item-content-checkbox"
							:class="marryId == item.id ? 'act' : ''" v-for="(item, index) in marryList" :key="index"
							@click="marryId = item.id">
							{{ item.value }}
						</view>
					</view>
				</view>
			</view>
			<!-- 高级筛选 -->
			<view class="index-singleranksetting-main" :class="is_vip == 0 ? 'opacity2' : ''"
				@click="is_vip == 0 ? opShow() : ''">
				<view class="index-singleranksetting-main-title u-flex u-row-between u-col-center">
					<view class="index-singleranksetting-main-title-content u-flex u-row-between">
						高级筛选
						<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/filter-vip.png"
							style="width: 80rpx;height: 32rpx;display: block;margin-left: 8px;" mode="">
						</image>
					</view>
					<view class="index-singleranksetting-main-title-search" @click="jumpSearch()">
						<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/filter-search.png" style="height: 40rpx;width: 40rpx;display: block;"
							mode="">
						</image>
					</view>
				</view>
				<!-- 收入范围(年) -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						收入范围(年)
					</view>
					<view class="index-singleranksetting-main-item-content">
						<range-slider :blockSize="32" width="680" step="1" :values="payRange" max="180" min="1"
							liveMode="true" @rangechange="onchangePay"></range-slider>
						<view class="u-flex u-row-between">
							<view class="">
								{{ payRange[0] }}W
							</view>
							<view class="">
								{{ payRange[1] }}W
							</view>
						</view>
					</view>
				</view>
				<!-- 家乡 -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						家乡
					</view>
					<view class="index-singleranksetting-main-item-content">
						<view class="index-singleranksetting-main-item-content-checkbox"
							:class="homelandId == item.id ? 'act' : ''" v-for="(item, index) in homelandList" :key="index"
							@click="homelandId = item.id">
							{{ item.name }}
						</view>
					</view>
				</view>
				<!-- 学校偏好（可多选） -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						学校偏好（可多选）
					</view>
					<view class="index-singleranksetting-main-item-content">
						<view class="index-singleranksetting-main-item-content-checkbox"
							:class="item.is_select == 1 ? 'act' : ''" v-for="(item, index) in schoolList" :key="index"
							@click="onChangeSchool(item, index)">
							{{ item.value }}
						</view>
					</view>
				</view>
				<!-- 个人标签 -->
				<view class="index-singleranksetting-main-item">
					<view class="index-singleranksetting-main-item-title">
						个人标签
					</view>
					<view class="index-singleranksetting-main-item-content">
						<view class="index-singleranksetting-main-item-content-checkbox"
							:class="item.is_select == 1 ? 'act' : ''" v-for="(item, index) in personalList" :key="index"
							@click="onChangeLabel(item, index)">
							{{ item.name }}
						</view>
					</view>
				</view>
			</view>
			<view class="index-singleranksetting-btn">
				<view class="index-singleranksetting-btn-item public-btn public-btn-color" @click="setFrom">
					确认
				</view>
				<view class="index-singleranksetting-btn-item public-btn" @click="reset">
					重置
				</view>
			</view>
		</scroll-view>
		<!-- <u-popup v-model="vipShow" mode="center" border-radius="20">
			<indexSingleranksettingVip></indexSingleranksettingVip>
		</u-popup> -->
	</view>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
import rangeSlider from '../../ex-components/range-slider/range-slider.vue'
import indexSingleranksettingVip from '../index-singleranksetting-vip/index-singleranksetting-vip.vue'

export default {
	// 组件名称
	name: 'demo',
	// 组件参数 接收来自父组件的数据
	props: {},
	// 局部注册的组件,import引入的组件需要注入到对象中才能使用
	components: {
		rangeSlider,
		indexSingleranksettingVip,
	},
	// 组件状态值
	data() {
		return {
			is_vip: 0,
			vipShow: false,
			ageRange: [18, 30],
			tallRange: [150, 190],
			payRange: [1, 50],
			educationId: -1,
			educationList: [],
			marryId: 2,
			marryList: [{
				id: 2,
				value: '均可'
			}, {
				id: 0,
				value: '仅接受未婚'
			}, {
				id: 1,
				value: '仅接受离异'
			}],
			homelandId: 0,
			homelandList: [],
			schoolId: 0,
			schools: [],
			schoolList: [{
				id: '',
				value: '不限'
			}, {
				id: 1,
				value: '一本以上'
			}, {
				id: 2,
				value: '985/211'
			}, {
				id: 3,
				value: '世界知名名校'
			}, {
				id: 4,
				value: '海归'
			}, {
				id: 5,
				value: '艺术体育类'
			},],
			personalId: 0,
			labels: [],
			personalList: [],
			from: {
				age: '', // 17,20  年龄
				height: '', // 170,180  身高
				education: -1, // -1均可0专科及以上，1本科及以上，2研究生及以上，3博士
				marriage: 2, // 0未，1离异，2均可
				home: '', // 2  家乡id
				money: '', // 5,10  收入
				label: '', // 9,13  标签
				school: '', // 1  学校id
				search: '', // 搜索关键词
			}
		}
	},
	// 计算属性
	computed: {},
	// 侦听器
	watch: {},
	// 组件方法
	methods: {
		opShow() {
			this.$emit('shows')
		},
		// 确认筛选
		setFrom() {
			this.from.height = this.tallRange.toString();
			this.from.age = this.ageRange.toString();
			this.from.education = this.educationId;
			this.from.marriage = this.marryId;
			if (this.is_vip == 1) {
				this.from.money = this.payRange.toString();
				this.from.home = this.homelandId;
				this.from.label = this.labels.toString();
				this.from.school = this.schools.toString();
			}


			console.log(this.from, 'from')
			// this.$emit('getFrom', this.from)
		},
		// 重置
		reset() {
			this.from = {
				age: '', // 17,20  年龄
				height: '', // 170,180  身高
				education: -1, // -1均可0专科及以上，1本科及以上，2研究生及以上，3博士
				marriage: 2, // 0未，1离异，2均可
				home: '', // 2  家乡id
				money: '', // 5,10  收入
				label: '', // 9,13  标签
				school: '', // 1  学校id
				search: '', // 搜索关键词
			}
			this.ageRange = [18, 30];
			this.tallRange = [150, 190];
			this.payRange = [1, 50];
			this.educationId = -1;
			this.marryId = 2;
			this.homelandId = 0;
			this.schoolId = 0;
			this.personalId = 0;
		},
		jumpSearch() {
			// this.vipShow = true
			this.$Router.push({
				path: '/pages/index/index/index-vipsearch',
			})
		},
		// 选择收入范围
		onchangePay(e) {
			this.payRange = [e.minValue, e.maxValue];
		},
		// 选择身高
		onchangeTall(e) {
			this.tallRange = [e.minValue, e.maxValue];
		},
		// 选择年龄
		onchangeAge(e) {
			this.ageRange = [e.minValue, e.maxValue];
		},
		// 选择学校
		onChangeSchool(e, i) {
			// console.log(e, 'eeee111', i)
			this.schoolList.filter((item, index) => {
				if (e.id == '') {
					this.schoolList.map(e => e.is_select = 0)
					this.schoolList[0].is_select = 1
					this.schools = []
				} else {
					this.schoolList[0].is_select = 0
					if (index == i) {
						this.schoolList[index].is_select = this.schoolList[index].is_select ? 0 : 1
						if (this.schools.indexOf(e.id) != -1) {
							this.schools.splice(this.schools.indexOf(e.id), 1)
							this.schoolList[index].is_select = 0
						} else {
							this.schools.push(e.id)
							this.schoolList[index].is_select = 1
						}
					}
				}
			})
			// console.log(this.schoolList, 'this.schoolList')
			this.$forceUpdate()
		},
		// 个人标签
		onChangeLabel(e, i) {
			// console.log(e, 'eeee222', i)
			this.personalList.filter((item, index) => {
				// 是否是不限
				if (e.id == '') {
					this.personalList.map(e => e.is_select = 0)
					this.personalList[0].is_select = 1
					this.labels = []
				} else {
					this.personalList[0].is_select = 0
					if (index == i) {
						this.personalList[index].is_select = this.personalList[index].is_select ? 0 : 1
						if (this.labels.indexOf(e.id) != -1) {
							this.labels.splice(this.labels.indexOf(e.id), 1)
							this.personalList[index].is_select = 0
						} else {
							this.labels.push(e.id)
							this.personalList[index].is_select = 1
						}
					}
				}
				return true
			})
			// console.log(this.personalList, 'this.personalList')
			this.$forceUpdate()
		},
		// 获取标签列表
		getLabel() {
			this.$http('config.label', {}, '').then(res => {
				// console.log(res, 'res')
				// this.labels = res.data.list
				this.personalList = res.data
				this.personalList.unshift({
					id: '',
					name: '不限'
				})
				// this.homelandList.map(e=>e.is_select = 0)
				this.personalList[this.personalId].is_select = 1
				// console.log(this.personalList, 'this.personalList')
			})
		},
		// 获取学历列表
		getEducation() {
			this.$http('config.education', {}, '').then(res => {
				// console.log(res, 'res')
				let obj = {
					id: '',
					name: ''
				}
				res.data.map((e,i)=>{
					// console.log(e)
					obj.id = i
					obj.name = e
					this.educationList.push(obj)
				})
				this.educationList.unshift({
					id: -1,
					name: '不限'
				})
			})
		},
		// 获取学校列表
		getSchool() {
			// this.$http('config.school', {}, '').then(res => {
			// 	console.log(res, 'res')
			// 	this.schools = res.data.list
			// 	this.schoolList = this.schoolList.concat(this.schools)
			// 	// console.log(this.schoolList, 'this.schoolList')
			// })
			this.schoolList[this.schoolId].is_select = 1
			// this.$forceUpdate()
		},
		// 获取地区
		getArea() {
			this.$http('config.area', {}, '').then(res => {
				// console.log(res, 'res')
				this.homelandList = res.data
				this.homelandList.unshift({
					id: '',
					name: '不限'
				})
				// this.homelandList.map(e=>e.is_select = 0)
				this.homelandList[this.homelandId].is_select = 1
				// this.schools = res.data.list
				// this.schoolList = this.schoolList.concat(this.schools)
				// console.log(this.schoolList, 'this.schoolList')
			})
		}
	},
	// 以下是生命周期钩子   注：没用到的钩子请自行删除
	/**
	 * 在实例初始化之后，组件属性计算之前，如data属性等
	 */
	beforeCreate() { },
	/**
	 * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
	 */
	created() {
		this.getSchool() // 获取学校
		this.getLabel() // 获取标签
		this.getArea() // 获取地区
		this.getEducation() // 获取学历
	},
	/**
	 * 在挂载开始之前被调用：相关的 render 函数首次被调用。
	 */
	beforeMount() { },
	/**
	 * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
	 * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
	 */
	mounted() { },
	/**
	 * 数据更新时调用，发生在虚拟 DOM 重新渲染和打补丁之前。
	 * 你可以在这个钩子中进一步地更改状态，这不会触发附加的重渲染过程。
	 */
	beforeUpdate() { },
	/**
	 * 由于数据更改导致的虚拟 DOM 重新渲染和打补丁，在这之后会调用该钩子。
	 * 当这个钩子被调用时，组件 DOM 已经更新，所以你现在可以执行依赖于 DOM 的操作。
	 */
	updated() { },
	/**
	 * keep-alive 组件激活时调用。 仅针对keep-alive 组件有效
	 */
	activated() { },
	/**
	 * keep-alive 组件停用时调用。 仅针对keep-alive 组件有效
	 */
	deactivated() { },
	/**
	 * 实例销毁之前调用。在这一步，实例仍然完全可用。
	 */
	beforeDestroy() { },
	/**
	 * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
	 * 所有的事件监听器会被移除，所有的子实例也会被销毁。
	 */
	destroyed() { }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<style scoped lang="scss">
.index-singleranksetting {
	padding: 0 32rpx;

	&-header {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		color: #2E3033;
		font-weight: 600;
		margin-top: 40rpx;
		text-align: center;
		margin-bottom: 40rpx;
	}

	&-main {
		&-title {
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #2E3033;
			margin-bottom: 40rpx;
		}

		&-item {
			margin-bottom: 60rpx;

			image {
				display: block;
			}

			&-title {
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				color: #5C5F66;
			}

			&-content {
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #5C5F66;

				&-checkbox {
					display: inline-block;
					min-width: 100rpx;
					line-height: 56rpx;
					margin-right: 20rpx;
					margin-top: 20rpx;
					padding: 0 20rpx;
					height: 56rpx;
					background: #F5F5F5;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					color: #737780FF;
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					text-align: center;
				}
			}

			.act {
				background: #7266FF;
				color: #fff;
			}
		}
	}

	&-btn {
		&-item {
			margin: 0 auto;
			margin-bottom: 40rpx;
		}
	}
}

.opacity2 {
	opacity: .6;
}
</style>
